import 'dart:convert';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:hc_cure_sdk_flutter/hc_cure_sdk_flutter.dart';
import 'package:hc_cure_sdk_flutter/model/cure/cure.dart';
import 'package:hc_cure_sdk_flutter/model/cure/treasures.dart';

import '../mixin/device_mixin.dart';
import 'sdk_service.dart';

class TherapyService with DeviceMixin {
  List<Therapy> _list = [];

  List<Therapy> get cahcedTherapyList => _list;

  Future refreshTherapyList() async {
    final sdk = Get.find<SDKService>();
    if (!sdk.isLoggedin) {
      await sdk.login();
    }

    _list = await HcCureSdkFlutter().fetchCures(userID: sdk.uuid);
  }

  List<Cure> get cachedCureList {
    List<Cure> ret = [];
    for (var e in _list) {
      ret.addAll(e.cures);
    }
    return ret;
  }

  Cure? pickCure(int cureID) {
    return cachedCureList.firstWhereOrNull((e) => e.id == cureID);
  }
}
